<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@page import="com.serviceprovider.business.utility.SecurityContextUser"%>
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
<%@include file="/WEB-INF/taglibs/common/taglibs.jsp"%>
	   <%--@elvariable id="states" type="java.util.List<State>"--%>
       <%--@elvariable id="roleList" type="java.util.List<Role>"--%>
       <%--@elvariable id="elements" type="com.serviceprovider.business.module.user.model.interfaces.IElements"--%>

<head>
<title><spring:message code="${elements.suffix}.create.user.title"/></title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" href="<c:url value="/css/styles.css"/>" />
<script src="<c:url value="/javascripts/common.js"/>" type="text/javascript"></script>
</head>

<c:if test="<%=SecurityContextUser.isAdmin()%>">
	<body onload="disableFeeField();">
	<%@include file="/WEB-INF/jsp/admin/top_menu.jsp"%>
</c:if>
<c:if test="<%=SecurityContextUser.isServiceProvider()%>">
     <body>
    <%@include file="/WEB-INF/jsp/serviceprovider/top_menu.jsp"%>
</c:if>
<c:if test="<%= !(SecurityContextUser.isAdmin() || SecurityContextUser.isServiceProvider()) %>">
	<body>
</c:if>


<table width=100%>
	<tr>
		<c:if test="<%=SecurityContextUser.isAdmin()%>">
		<td><c:import url="/WEB-INF/jsp/menu/admin_users_menu.jsp" /><br /></td>
		</c:if>
		<c:if test="<%=SecurityContextUser.isServiceProvider()%>">
		<td><c:import url="/WEB-INF/jsp/menu/sp_users_menu.jsp" /><br /></td>
		</c:if>		
	</tr>
 		<tr>
		<td><%@include file="/WEB-INF/jsp/include/messages.jsp"%>
		<br />
		</td>
	</tr>
</table>
<form:form commandName="userForm" method="post" onsubmit="return validatePassword()">
	<table width=70% class="formTable">

		<tr class="formHeader">
			<td colspan="2" align="left"><b><spring:message code="${elements.suffix}.create.user.create"/></b></td>
		</tr>
		<tr>
			<td align="left" width="175px"><div id="roleCreateComboLabelId" style="display: ${elements.roleCreateComboLabel}">
				<span style="color: red; ">*</span><spring:message code="${elements.suffix}.create.user.role"/></div>
			</td>
			<td><div id="roleCreateComboId" style="display: ${elements.roleCreateCombo}">
				<form:select path="roleId" onchange="disableFeeField();">
				<c:forEach items="${roleList}" var="item" varStatus="i">
					<form:option value="${item.id}" id="optionId_${item.id}">${item.name}</form:option>
				</c:forEach>
				</form:select></div>
			</td>
		</tr>
        <c:if test="<%=SecurityContextUser.isAdmin()%>">
		
        <tr>
		    <td><div id="level1UsersComboLabelId" style="display: ${elements.level1UsersComboLabel}">
			    <span style="color: red; ">*</span><spring:message code="${elements.suffix}.create.user.details.level1user"/></div>
		    </td>
		    <td><div id="level1UsersComboId" style="display: ${elements.level1UsersCombo}">
			    <form:select path="level1User.id" cssStyle="width: 218px;">
			    <form:option value="0"><spring:message code="${elements.suffix}.create.user.details.level1None"/></form:option>
				    <c:forEach items="${level1Users.pageItems}" var="item" varStatus="i">
					    <form:option value="${item.id}">${item.firstName} ${item.lastName}</form:option>
				    </c:forEach>
			    </form:select></div>
		    </td>
	    </tr>
        </c:if>
        <c:if test="<%=SecurityContextUser.isServiceProvider()%>">
		    <form:hidden path="level1User.id"/>
		</c:if>
		<tr>
			<td><span style="color: red; ">*</span><spring:message code="${elements.suffix}.create.user.email"/></td>
			<td><form:input path="email" size="40" maxlength="40"/>
			<div class="errors"><form:errors path="email" /></div>
			</td>
		</tr>

		<tr>
			<td><span style="color: red; ">*</span><spring:message code="${elements.suffix}.create.user.password"/></td>
			<td><form:password path="password" size="40" maxlength="40"/>
			<div class="errors"><form:errors path="password" /></div>
			</td>
		</tr>
	<tr>
			<td><span style="color: red; ">*</span><spring:message code="${elements.suffix}.create.user.confirmpassword"/></td>
			<td><form:password path="confirmPassword" size="40" maxlength="40"/>
			<div class="errors"><form:errors path="confirmPassword" /></div>
			</td>
		</tr>
		<tr>
			<td><span style="color: red; ">*</span><spring:message code="${elements.suffix}.create.user.firstName"/></td>
			<td><form:input path="firstName" size="40" maxlength="40"/>
			<div class="errors"><form:errors path="firstName" /></div>
			</td>
		</tr>
		<tr>
			<td><span style="color: red; ">&nbsp;</span><spring:message code="${elements.suffix}.create.user.middleName"/></td>
			<td><form:input path="milddleName" size="40" maxlength="40"/>
			</td>
		</tr>		
		<tr>
			<td><span style="color: red; ">*</span><spring:message code="${elements.suffix}.create.user.lastName"/></td>
			<td><form:input path="lastName" size="40" maxlength="40"/>
			<div class="errors"><form:errors path="lastName" /></div>
			</td>
		</tr>
		<tr>
			<td><span style="color: red; ">&nbsp;</span><spring:message code="${elements.suffix}.create.user.efin"/></td>
			<td><form:input path="efin" size="40" maxlength="9" alt="9 digit number"/>
			<div class="errors"><form:errors path="efin" /></div>
			</td>
		</tr>
		<tr>
			<td><spring:message code="${elements.suffix}.create.user.businessName"/></td>
			<td><form:input path="businessName" size="40" maxlength="40"/>
			<div class="errors"><form:errors path="businessName" /></div>
			</td>
		</tr>	
		<tr>
			<td><spring:message code="${elements.suffix}.create.user.businessfein"/></td>
			<td><form:input path="businessFein" size="40" maxlength="15"/>
			<div class="errors"><form:errors path="businessFein" /></div>
			</td>
		</tr>	
		<tr>
			<td><spring:message code="${elements.suffix}.create.user.ownerssn"/></td>
			<td><form:input path="ownerSsn" size="40" maxlength="9"/>
			<div class="errors"><form:errors path="ownerSsn" /></div>
			</td>
		</tr>	
		<tr id="feeId">
			<td><div id="feeLabelId" style="display: ${elements.feeLabel}">
				<span style="color: red; "></span><spring:message code="${elements.suffix}.create.user.fee"/></div>
			</td>
			<td><div id="feeValueId" style="display: ${elements.feeValue}">
				<form:input path="fee" size="39"  maxlength="9"/>
				<div class="errors"><form:errors path="fee" /></div></div>
			</td>
		</tr>
    <c:if test="<%=SecurityContextUser.isAdmin()%>">
        <tr id="orderApproval">
			<td><span style="color: red; ">&nbsp;</span><spring:message code="admin.create.user.orderapproval"/></td>
			<td><table border="0" width="50%"><tr>
                    <td width="50%"><form:radiobutton path="orderApproval" value="1"/><spring:message code="admin.create.user.orderapproval.auto"/></td>
                    <td><form:radiobutton path="orderApproval" value="2"/><spring:message code="admin.create.user.orderapproval.manual"/></td>
                </tr></table>
            </td>
		</tr>

        <tr id="checkPrinting">
			<td><span style="color: red; ">&nbsp;</span><spring:message code="admin.create.user.checkprintingby"/></td>
			<td><table border="0" width="50%"><tr>
                    <td width="50%"><form:radiobutton path="checkPrintingBy" value="1"/><spring:message code="admin.create.user.checkprintingby.admin"/></td>
                    <td><form:radiobutton path="checkPrintingBy" value="2"/><spring:message code="admin.create.user.checkprintingby.sp"/></td>
                </tr></table>
            </td>
		</tr>
    </c:if>
		<tr>
			<td><span style="color: red; ">&nbsp;</span><spring:message code="${elements.suffix}.create.user.active"/></td>
			<td><form:checkbox path="enabled" value=""/> <font color=red><spring:message code="${elements.suffix}.create.user.message"/></font></td>
		</tr>

		<tr>
			<td colspan="2">&nbsp;</td>
		</tr>

		<tr>
			<td colspan="2" align="center"><input type="submit" class='ui-button ui-state-default ui-corner-all'
				id="createUser" value="Save" /> <input type="button" class='ui-button ui-state-default ui-corner-all' value="Cancel"
				onclick="location.href='view_users.htm'" /></td>
		</tr>
	</table>
</form:form>
<script language="javascript" type="text/javascript">
	function validatePassword() {
		var password1 = document.getElementById("password").value;
		var password2 = document.getElementById("confirmPassword").value;
		
		if (password1 != password2) {
			alert("Please enter password and confirm password the same value");
			return false;
		}
		return true;
	}
	
	function disableFeeField() {
		var roleId = document.getElementById("roleId").value;
		var role = document.getElementById("optionId_" + roleId).text;
		if(role == "ROLE_SERVICE_PROVIDER") {
			document.getElementById("feeId").style.display = '';
            document.getElementById("orderApproval").style.display = '';
            document.getElementById("checkPrinting").style.display = '';
		} else {
            document.getElementById("feeId").style.display = 'none';
            document.getElementById("orderApproval").style.display = 'none';
            document.getElementById("checkPrinting").style.display = 'none';
		}
	}
</script>
<%@include file="/WEB-INF/jsp/include/footer.jsp"%>
</body>
</html>